package com.leiyuan.content.controller;

import com.leiyuan.content.service.CourseTeacherService;
import com.leiyuan.dto.CourseTeacherDto;
import com.leiyuan.po.CourseTeacher;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 课程-教师关系接口
 *
 * @author leiyuan
 * @version 1.0
 */
@Slf4j
@Api(value = "课程教师编辑接口",tags = "课程教师编辑接口")
@RestController
@RequestMapping("courseTeacher")
public class CourseTeacherController {

    @Autowired
    private CourseTeacherService courseTeacherService;

    @ApiOperation(value = "查询课程教师信息")
    @GetMapping("/list/{courseId}")
    public List<CourseTeacherDto> getCourseTeacher(@PathVariable Long courseId){
        log.info("查询课程id为{}的教师信息",courseId);
        return courseTeacherService.queryCourseTeacher(courseId);
    }

    /**
     * 新增课程教师信息
     * 前端新增、修改共用接口
     *
     * @param courseTeacherDto
     * @return void
     * @author leiyuan
    */
    @ApiOperation(value = "新增课程教师信息")
    @PostMapping
    public void saveCourseTeacher(@RequestBody CourseTeacherDto courseTeacherDto){
        log.info("新增课程教师信息：{}",courseTeacherDto);
        courseTeacherService.createCourseTeacher(courseTeacherDto);
    }

    @ApiOperation(value = "删除课程教师信息接口")
    @DeleteMapping("/course/{courseId}/{id}")
    public void delCourseTeacher(@PathVariable Long courseId, @PathVariable Long id){
        log.info("删除课程id为{}，id为{}的课程教师信息",courseId,id);
        courseTeacherService.removeCourseTeacher(courseId,id);
    }
}
